<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<style>
    #commentForm .main-container .short_table_list .opt-btn-group{border-bottom: none !important;}
</style>
<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>编辑离职信息</span><?php include "../public/sub.php";?></div></div>
    <div class="main-container">
        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">人员姓名</label>
                        <div class="layui-input-block">
                            <input type="text" id="name" readonly placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>人员状态</label>
                        <div class="layui-input-block">
                            <select id="state" name="state" lay-filter="state" ></select>
                            <p class="error" id="state_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item statelizhi layui-hide">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">离职日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="outdt" id="outdt" placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
<!--            <div class="layui-form-item statelizhi layui-hide">-->
<!--                <div class="layui-row layui-col-space10">-->
<!--                    <div class="layui-col-md12">-->
<!--                        <label class="layui-form-label">离职说明</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="text" name="outexp" id="outexp" placeholder="请输入" clearable autocomplete="off" class="layui-input">-->
<!--                        </div>-->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>社保状态</label>
                        <div class="layui-input-block">
                            <select id="social" name="social" lay-filter="social" ></select>
                            <p class="error" id="social_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">参保开始月份</label>
                        <div class="layui-input-block">
                            <input type="text" name="socstartdt" id="socstartdt" placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ym">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">参保结束月份</label>
                        <div class="layui-input-block">
                            <input type="text" name="socenddt" id="socenddt" placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ym">
                        </div>
                    </div>
                </div>
            </div>


            <div class="layui-form-item">
                <div class="short_table_list" key="2">
                    <div class="opt-btn-group">
                        <div><span>转出证书</span></div>
                    </div>
                    <table class="layui-table" lay-size="sm">
                        <thead>
                        <tr>
                            <th style="width: 45px;">序号</th>
                            <th>证书名称</th>
                            <th>证书专业</th>
                            <th>证书编号</th>
                            <th>证书去向</th>
                            <th>用证状态</th>
                            <th>证书状态</th>
                            <th>转出/注销时间</th>
                        </tr>
                        </thead>
                        <tbody class="short_table_tbody" id="cert">
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</form>
<script>
    var param_id = getQueryVariable('id') || 0;

    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    month = month < 10 ? '0'+month : month;
    var day = date.getDate();
    var endDate = year + '-' + month + '-' + day;
    $('.bdate_ymd').datetimepicker({
        language: 'zh-CN',//显示中文
        format: 'yyyy-mm-dd',//显示格式
        minView: "month",//设置只显示到月份
        initialDate: new Date(),//初始化当前日期
        autoclose: true,//选中自动关闭
        todayBtn: true,//显示今日按钮
        endDate: endDate
    });


    layui.use(['laytp', 'form'], function() {
        var form = layui.form;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_person_editout, data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;

                $("#name").val(data.name);
                $("#outdt").val(data.outdt);
                // $("#outexp").val(data.outexp);
                $("#socstartdt").val(data.socstartdt);
                $("#socenddt").val(data.socenddt);

                if(data.state == '离职'){
                    $('.statelizhi').removeClass('layui-hide');
                }else{
                    $('.statelizhi').addClass('layui-hide');
                }


                xiala_zhan_one_you('state', res.data.state, data.state);
                xiala_zhan_one_you('social', res.data.social, data.social);

                var cert_state = res.data.cert_state;
                var cert_data = res.data.cert_data;
                var str = '';
                for(var i=0;i<cert_data.length;i++){
                    str += '<tr>';
                    str += '<td style="width: 45px">'+(i+1)+'</td>';
                    str += '<td>'+cert_data[i].name+'</td>';
                    str += '<td>'+cert_data[i].major+'</td>';
                    str += '<td>'+cert_data[i].number+'</td>';
                    str += '<td>'+cert_data[i].goes+'</td>';
                    str += '<td>'+cert_data[i].statueuse+'</td>';
                    str += '<td><select class="layui-select cert_state">';
                    for (let j in cert_state){
                        str += '<option value="'+cert_state[j]+'">'+cert_state[j]+'</option>';
                    }
                    str += '</select></td>';
                    str += '<td><input type="text" class="layui-input out_dt bdate_ymd" value="'+cert_data[i].out_dt+'" key="'+cert_data[i].id+'"></td>';
                    str += '</tr>';
                }
                $('.short_table_tbody').html(str);



                $('.bdate_ymd').datetimepicker({
                    language: 'zh-CN',//显示中文
                    format: 'yyyy-mm-dd',//显示格式
                    minView: "month",//设置只显示到月份
                    initialDate: new Date(),//初始化当前日期
                    autoclose: true,//选中自动关闭
                    todayBtn: true,//显示今日按钮
                    endDate: endDate
                });
                render_from();
            }
        });


        form.on('select(state)', function(data){
            if(data.value === '离职'){
                $('.statelizhi').removeClass('layui-hide');
            }else{
                $('.statelizhi').addClass('layui-hide');
            }
            if(data.value == ''){
                $('#state_error').show().text('请选择');
                $('#state_error').parent().find('input').addClass('select_error');
            }else{
                $('#state_error').hide();
                $('#state_error').parent().find('input').removeClass('select_error');
            }
        });

        form.on('select(social)', function(data){
            if(data.value == ''){
                $('#social_error').show().text('请选择');
                $('#social_error').parent().find('input').addClass('select_error');
            }else{
                $('#social_error').hide();
                $('#social_error').parent().find('input').removeClass('select_error');
            }
        });

        form.on('submit(add)', function(data){
            var cert_list = [''];
            $('#cert tr').each(function () {
                var out_dt = $(this).find('.out_dt').val();
                var state = $(this).find('.cert_state').val();
                var id = $(this).find('.out_dt').attr('key');
                var arr = {
                    out_dt: out_dt,
                    state: state,
                    id: id
                };
                cert_list.push(arr);
            });
            data.field.cert_list = cert_list;


            if(data.field.state == '在职'){
                data.field.outdt = '';
                // data.field.outexp = '';
            }

            data.field.id = param_id;
            facade.ajax({url: ask_person_editout, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });

</script>
</body>
</html>
